define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'apiconfig/index',
                    add_url: 'apiconfig/add',
                    edit_url: 'apiconfig/edit',
/*                     del_url: 'apiconfig/del',
                    multi_url: 'apiconfig/multi', */
                    table: 'apiconfig',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                       /*  {field: 'id', title: __('Id')},
                        {field: 'admin_id', title: __('Admin_id')}, */
                        {field: 'apisn', title: __('Apisn')},
                        {field: 'apiname', title: __('Apiname')},
                        {field: 'apiurl', title: __('Apiurl'), formatter: Table.api.formatter.url},
                        {field: 'apitimesperday', title: __('Apitimesperday')},
                        {field: 'apiversion', title: __('Apiversion')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        /* {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime}, 
                        {field: 'field1', title: __('Field1')},
                        {field: 'field2', title: __('Field2')},
                        {field: 'field3', title: __('Field3')},
                        {field: 'field4', title: __('Field4')},
                        {field: 'field5', title: __('Field5')},*/
                        {field: 'weigh', title: __('Weigh')},
                        {field: 'state', title: __('State'), visible:false, searchList: {"state 0":__('State 0'),"state 1":__('State 1')}},
                        {field: 'state_text', title: __('State'), operate:false},
                        /* {field: 'memo', title: __('Memo')}, */
                        {field: 'logstate', title: __('Logstate'), visible:false, searchList: {"logstate 0":__('Logstate 0'),"logstate 1":__('Logstate 1')}},
                        {field: 'logstate_text', title: __('Logstate'), operate:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});